Skip to main content link. Accesskey S
  • Help
  • HCL Logo
  • HCL Lotus Expeditor wiki
  • THIS WIKI IS READ-ONLY. Individual names altered for privacy purposes.
  • HCL forums and blogs
  • Home
  • Product Documentation
  • Community Articles
Search
Community Articles > Expeditor Client for Desktop > Sample: Toolbar and Menu Contributions
  • Share Show Menu▼
  • Subscribe Show Menu▼

Recent articles by this author

Sample: Toolbar and Menu Contributions

Expeditor user interface team best practices on toolbar and menu contributions

Sample: Component Properties

OverviewComponent properties allow developers to create code that at compile time has specific function but accepts flexible input at runtime. For example, a developer can create a component that uses a predefined component property to update the title tab's text within a composite ...

Sample: Multiuser Features

Overview When multiple users share the same workstation, the configuration is referred to as a multiuser installation. This means that a single Expeditor client exists and is shared among all users; however, each user has their own workspace containing configuration details specific to that ...

Sample: Starting Plugins

Overview By default, Eclipse plugins are lazy. Lazy is the technical term (located in the bundle's manifest) that means that plugins are started when a request is either directly made by the Platform to start the plugin or indirectly through class loading. For example, the latter case implies ...

Sample: HTTP Communication

Overview The enhanced HTTP client in Expeditor allows developers to quickly create code that requests data from remote servers over HTTP or HTTPS. The enhanced client wraps the standard Java URLConnectionclasses such that authenticated requests leverage the Accounts framework and HTTPS ...
Community articleSample: Toolbar and Menu Contributions
Added by ~Tip Desachekli | Edited by ~Tip Desachekli on February 9, 2012 | Version 4
  • Actions Show Menu▼
expanded Abstract
collapsed Abstract
Expeditor user interface team best practices on toolbar and menu contributions
Tags: samples
ShowTable of Contents
HideTable of Contents
  • 1 Overview
  • 2 Global Toolbar
    • 2.1 Toolbar Action
    • 2.2 Toggle ActionSet Action
    • 2.3 Composite Applications and Activities
  • 3 View Toolbars
    • 3.1 View ToolBar Action and View Menu Action

Overview


The various options available when contributing toolbars and menus can be confusing when developing Expeditor applications. To simplify the process of contributing these items, the Expeditor user interface team recommends the following best practices. Sample code has been provided below to demonstrate the following decorations to the user interface:

Toolbar ActionA rich SWT control added using a controlSet
Toggle Action Set ActionAn action contributed using an actionSet
View ToolBar ActionAn action added to a ViewPart's toolbar
View Menu ActionAn action added to a ViewPart's menu



Global Toolbar

  1. Use org.eclipse.ui.actionSets, if the developer wants to add regular/standard type of toolbar button such as push, radio, toggle, pulldown buttons
  2. Use com.ibm.rcp.ui.controlSets, if the developer wants to add arbitrary SWT control to toolbar, such as Text, Combo, StyledText, Browser controls
  3. The extension point org.eclipse.ui.menus is not supported for the global toolbar in Expeditor

Toolbar Action


The "Toolbar Action" is added using the controlSet extension point detailed in the Expeditor wiki article Contributing custom controls to the main toolbar staticallyCreate New Article. To add the "Toolbar Action", declare a controlSet, contribute a toolbar, and finally add the control to the toolbar. Valid entries for the path are: BEGIN_GROUP, MIDDLE_GROUP, END_GROUP.

<extension
         point="com.ibm.rcp.ui.controlSets">
      <controlSet
            align="left"
            id="com.ibm.rcp.support.menu.controlset"
            label="Toolbar Samples"
            showInToolBarMenu="true"
            tooltip="Displays toolbar contributions"
            visible="true">
         <toolBar
               id="com.ibm.rcp.support.menu.globaltoolbar"
               path="BEGIN_GROUP">
         </toolBar>
         <control
               class="com.ibm.rcp.support.menu.globaltoolbar.ToolbarAction"
               id="com.ibm.rcp.support.menu.globaltoolbar.control"
               toolbarPath="com.ibm.rcp.support.menu.globaltoolbar">
         </control>
      </controlSet>
   </extension>


The "Toolbar Action" class snippet is below.


public class ToolbarAction extends ContributionItem implements
		ISContributionItem {

	private SToolItem item;

	private final Image icon = Activator.imageDescriptorFromPlugin(
			Activator.PLUGIN_ID, "icons" + File.separator + "notes_icon.gif")
			.createImage();

	public void fill(final SToolBar bar, int index) {
		item = new SToolItem(bar, SWT.PUSH);
		item.setText("Toolbar Action");
		item.setToolTipText("A toolbar contribution");
		item.setImage(icon);

		item.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetDefaultSelected(SelectionEvent event) {
				// no default
			}

			@Override
			public void widgetSelected(SelectionEvent event) {
				Item i = ((Item) event.getSource());
				ActionContributionItem actionContrib = (ActionContributionItem) i
						.getData();

				doSomething(item, actionContrib);
			}
		});
	}

	@Override
	public void fill(SCoolBar parent, int index) {

	}

	public void dispose() {
		icon.dispose();
	}

...


Toggle ActionSet Action


The "Toggle ActionSet Action" is provided as an advanced sample of the Contributing Eclipse-based controls to the toolbar staticallyCreate New Article wiki article. Depending on the context, some actions may need to be hidden. For example, a composite application may need to show one action while another may need to hide an action and show another. This showing and hiding is accomplished using Eclipse activities. Toolbar actions are associated with an activity, and when required to show, the corresponding activity is enabled.

The following extensions create the "Toggle ActionSet Action" as well as the "ActionSet Action". Initially the "Toggle ActionSet Action" is the only action visible.

<extension
         point="org.eclipse.ui.actionSets">
      <actionSet
            id="com.ibm.rcp.support.menu.actionset"
            label="ActionSet Action"
            visible="true">
         <action
               class="com.ibm.rcp.support.menu.ActionSetAction"
               id="com.ibm.rcp.support.menu.actionset.action"
               label="ActionSet Action"
               style="push"
               toolbarPath="END_GROUP">
         </action>
         <action
               class="com.ibm.rcp.support.menu.ActionSetToggle"
               id="com.ibm.rcp.support.menu.actionset.action.toggle"
               label="Toggle ActionSet Action"
               style="push"
               toolbarPath="END_GROUP">
         </action>
      </actionSet>
   </extension>


Both classes simply implement the org.eclipse.ui.IWorkbenchWindowActionDelegate interface. The "ActionSet Action" is added to an Eclipse activity.

<extension 
	   point="org.eclipse.ui.activities">
  	<activity 
		id="com.ibm.rcp.support.menu.activity" 
		name="Action Set" /> 
  	<activityPatternBinding 
		activityId="com.ibm.rcp.support.menu.activity" 
		isEqualityPattern="false" 
		pattern="com\.ibm\.rcp\.support\.menu/com\.ibm\.rcp\.support\.menu\.actionset\.action" /> 
  </extension>


The pattern is a regular expression; it declares pluginID/actionID. By enabling the activity com.ibm.rcp.support.menu.activity, the Eclipse action defined by the ID com.ibm.rcp.support.menu.actionset.action in the plugin com.ibm.rcp.support.menu is shown. And this is exactly what the "Toggle ActionSet Action" button does, it enables the activity which shows the "ActionSet Action".

// the activity ID from the plugin.xml
// this binds the actionSet contribution to the activity
String id = "com.ibm.rcp.support.menu.activity";

IWorkbenchActivitySupport s = PlatformUI.getWorkbench()
	.getActivitySupport();
IActivityManager m = s.getActivityManager();

IActivity a = m.getActivity(id);

// toggle
if (a != null) {
	Set enabled;
			if (a.isEnabled()) {
		enabled = new HashSet(m.getEnabledActivityIds());
		enabled.remove(id);
	} else {
		enabled = new HashSet(m.getEnabledActivityIds());
		enabled.add(id);
	}
	
	s.setEnabledActivityIds(enabled);
}


Composite Applications and Activities


Expeditor Composite Applications can enable and disable activities. For example when a Composite Application is shown, the activity is enabled, and when the Composite Application is closed or deactivated, the activity is disabled. This gives the show-hide context described earlier. To bind a particular Composite Application to an activity, edit the Composite Application's page properties - activities are defined at the page level not the application level. Add the property com.ibm.rcp.activities=activityId. Multiple activities can be delimited by the token colon colon (::).

View Toolbars

  1. Use org.eclipse.ui.viewActions, if the developer wants to add regular/standard type of toolbar button such as push, radio, toggle, pulldown buttons.
  2. Call IViewSite.getActionBars().getToolbarManager() and add a contribution to the toolbar manager , if the developer wants to add arbitrary SWT control to toolbar, such as Text, Combo, StyledText, Browser controls.
  3. Extension point org.eclipse.ui.menus is not supported for a view's toolbar in Expeditor.

View ToolBar Action and View Menu Action


The "View ToolBar Action" and "View Menu Action" are added programmatically using method two described above. The code for doing this is relatively straightforward and has been provided as part of a ViewPart's creation method.


public void createPartControl(Composite parent) {
	// get menu managers
	org.eclipse.jface.action.IToolBarManager toolBar = super.getViewSite()
			.getActionBars().getToolBarManager();

	org.eclipse.jface.action.IMenuManager menuBar = getViewSite()
			.getActionBars().getMenuManager();

	// create actions
	org.eclipse.jface.action.Action toolAction = new Action() {
		public void run() {
			// do something
		}
	};
	toolAction.setText("View ToolBar Action");

	org.eclipse.jface.action.Action menuAction = new Action() {
		public void run() {
			// do something
		}
	};
	menuAction.setText("View Menu Action");

	// add actions to menu managers
	toolBar.add(toolAction);
	menuBar.add(menuAction);
}





  • Actions Show Menu▼


expanded Attachments (0)
collapsed Attachments (0)
Edit the article to add or modify attachments.
expanded Versions (4)
collapsed Versions (4)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (4)Feb 9, 2012, 5:15:38 PM~Tip Desachekli  
3Feb 9, 2012, 5:02:33 PM~Tip Desachekli  
2Feb 9, 2012, 4:32:19 PM~Tip Desachekli  
1Feb 9, 2012, 4:24:36 PM~Tip Desachekli  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedAbout
  • HCL Software
  • HCL Digital Solutions community
  • HCL Software Support
  • BlogsDigital Solutions blog
  • Community LinkHCL Software forums and blogs
  • About HCL Software
  • Privacy
  • Accessibility